﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Common;

namespace Model
{
    public class OptionDAO
    {
        private static string optionPath=PubConstant.ConfigPath+PubConstant.AppOptionsName;
        private static XmlDocument doc;

        /// <summary>
        /// 获取项目路径（默认为程序的Project文件夹）
        /// </summary>
        /// <param name="IsDefault"></param>
        /// <returns></returns>
        public string GetProjectPath()
        {
            try
            {
              doc.Load(optionPath);
              XmlNode xnD = doc.SelectSingleNode("//Options//ProjectPath//UserCustom");
              if(String.IsNullOrEmpty(xnD.InnerText))
              {
                 XmlNode xnU=doc.SelectSingleNode("//Options//ProjectPath//Default");
                 return xnU.InnerText;
              }
              else
              {
                  return xnD.InnerText;
              }
              
              
            }
            catch (Exception ex)
            {
                
                throw ex; 
            }

        }

        /// <summary>
        /// 设置项目路径
        /// </summary>
        /// <param name="path"></param>
        public void SetProjectPath(string path)
        {
            try
            {
                doc.Load(optionPath);
                XmlNode xn = doc.SelectSingleNode("//Options//ProjectPath//UserCustom");
                if (String.IsNullOrEmpty(path))
                {
                    xn.InnerText = "";
                }
                else
                {
                    if (String.Compare(path.Substring(path.Length - 2, path.Length - 1), "\\", false) != 0)
                    {
                        xn.InnerText = path+"\\";
                    }
                }
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
        }

    }
}
